<button nz-button nzType="primary" (click)="addNewOrganization()">新增</button>
<!-- <button nz-button nzType="primary" nzDanger (click)="delelte()">
  删除
</button>
<button nz-button nzType="primary" (click)="isVisibleReportManagerTree=true;">
  汇报关系树
</button>
<button nz-button nzType="primary" (click)="showSetPermissionModal()">模型权限</button> -->

<!-- <button nz-button nzType="primary" (click)="setModelPermission()">
  查看模型权限
</button> -->

<nz-divider nzOrientation="left" nzText=""></nz-divider>
<div nz-row>
  <div nz-col [nzSpan]="18" [nzPush]="6">
    <nz-card nzTitle="基本信息" nzSize="small" [nzExtra]="extraTemplate">
      <div nz-row>
        <div nz-col nzSpan="8">
          名称：{{selectedEmployee?.name
          }}
          <a
            nz-tooltip
            nzTooltipTitle="查看个人汇报线"
            (click)="isVisibleMyReportLine=true"
            ><i nz-icon nzType="apartment" nzTheme="outline"></i></a>
        </div>
        <div nz-col nzSpan="8">
          工号：{{
            selectedEmployee?.code
          }}
        </div>
        <div nz-col nsSpan="8">
          主组织：{{
            selectedEmployee?.org.name
          }}
          <a
            nz-tooltip
            nzTooltipTitle="设置主组织"
            (click)="showOrganizationEdit()"
            ><i nz-icon nzType="edit" nzTheme="outline"></i
          ></a>
        </div>
      </div>

      <div nz-row>
        <div nz-col nzSpan="8">
          岗位：
          <ng-container
            *ngFor="
              let role of selectedEmployee?.roles
            "
          >
            {{ role.role.name }},
          </ng-container>
          <a nz-tooltip nzTooltipTitle="设置岗位" (click)="showSetRole()">
            <i nz-icon nzType="edit" nzTheme="outline"></i>
          </a>
        </div>
        <div nz-col nzSpan="8">
          级别：
          <ng-container
            *ngFor="
              let orgLevel of selectedEmployee?.levels
            "
          >
            {{ orgLevel.level.name }},
          </ng-container>
          <a nz-tooltip nzTooltipTitle="设置级别" (click)="showSetLevel()">
            <i nz-icon nzType="edit" nzTheme="outline"></i>
          </a>
        </div>
        <div nz-col nzSpan="8">
          汇报上级：
          <ng-container
            *ngFor="
              let orgLevel of selectedEmployee?.parents
            "
          >
            {{ orgLevel.name }},
          </ng-container>
          <a nz-tooltip nzTooltipTitle="设置上级" (click)="showSetReportManager()">
            <i nz-icon nzType="edit" nzTheme="outline"></i>
          </a>
        </div>
        <div nz-col nzSpan="8">
          创建时间：{{
            selectedEmployee?.modifiedBy
          }}
        </div>
      </div>

      <div nz-row>
        <div nz-col nzSpan="8">
          创建者：{{
            selectedEmployee?.createdBy
          }}
        </div>
        <div nz-col nzSpan="8">
          最后更新时间：{{
            selectedEmployee?.modifiedDate
          }}
        </div>
        <div nz-col nzSpan="8">
          最后更新者：{{
            selectedEmployee?.modifiedBy
          }}
        </div>
      </div>
    </nz-card>
    <ng-template #extraTemplate>
      <ng-container *ngIf="this.treeService.selectListSelection.selected.length>0">
      <!-- <a nz-tooltip nzTooltipTitle="数据授权" (click)="showSetDataPermissionModal()"
        ><i nz-icon nzType="safety-certificate" nzTheme="outline"></i
      ></a> -->
      <a nz-tooltip nzTooltipTitle="编辑"
        ><i nz-icon nzType="edit" nzTheme="outline"></i
      ></a>
      <!-- <a nz-tooltip nzTooltipTitle="查看数据权限"
        ><i nz-icon nzType="eye" nzTheme="outline"></i
      ></a> -->
    </ng-container>
    </ng-template>
  </div>
  <div nz-col [nzSpan]="6" [nzPull]="18">
    <nz-tree-view [nzTreeControl]="treeService.treeControl" [nzDataSource]="dataSource">
      <nz-tree-node *nzTreeNodeDef="let node" nzTreeNodeIndentLine>
        <!-- <nz-tree-node-checkbox
          [nzDisabled]="node.expandable||node.type==='ORG'"
          [nzChecked]="treeService.checklistSelection.isSelected(node)"
          (nzClick)="treeService.leafItemSelectionToggle(node)"
        ></nz-tree-node-checkbox> -->
        <nz-tree-node-option
          [nzDisabled]="node.type==='ORG'"
          [nzSelected]="treeService.selectListSelection.isSelected(node)"
          (nzClick)="onItemSelect(node)"
        >
          {{ node.label }}
        </nz-tree-node-option>
      </nz-tree-node>

      <nz-tree-node *nzTreeNodeDef="let node; when: hasChild" nzTreeNodePadding>
        <nz-tree-node-toggle>
          <i nz-icon nzType="caret-down" nzTreeNodeToggleRotateIcon></i>
        </nz-tree-node-toggle>
        <!-- <nz-tree-node-checkbox
          [nzDisabled]="node.expandable||node.type==='ORG'"
          [nzChecked]="treeService.descendantsAllSelected(node)"
          [nzIndeterminate]="treeService.descendantsPartiallySelected(node)"
          (nzClick)="treeService.itemSelectionToggle(node)"
        >
        </nz-tree-node-checkbox> -->
        <nz-tree-node-option
          [nzDisabled]="node.type==='ORG'"
          [nzSelected]="treeService.selectListSelection.isSelected(node)"
          (nzClick)="onItemSelect(node)"
        >
        {{ node.label }}
        </nz-tree-node-option>
      </nz-tree-node>
    </nz-tree-view>
  </div>
</div>

<nz-modal
  [(nzVisible)]="isNewVisible"
  nzTitle="新增"
  (nzOnCancel)="handleCancel()"
  (nzOnOk) = "submitForm()"
>
  <nz-content *nzModalContent>
    <form
      nz-form
      nzLayout="vertical"
      [formGroup]="validateForm"
    >
      <nz-form-item>
        <nz-form-label>名称</nz-form-label>
        <nz-form-control nzErrorTip="">
          <input nz-input formControlName="name" placeholder="请输入名称" />
        </nz-form-control>
      </nz-form-item>

      <nz-form-item>
        <nz-form-label>工号</nz-form-label>
        <nz-form-control nzErrorTip="">
          <input nz-input formControlName="code" placeholder="请输入工号" />
        </nz-form-control>
      </nz-form-item>

      <nz-form-item>
        <nz-form-label>所属主组织：</nz-form-label>
        <app-organization-search></app-organization-search>
      </nz-form-item>

      <!-- <nz-form-item>
        <nz-form-label>担任岗位：</nz-form-label>
        <app-role-search></app-role-search>
      </nz-form-item>

      <nz-form-item>
        <nz-form-label>行政级别：</nz-form-label>
        <app-level-search></app-level-search>
      </nz-form-item> -->

      <!-- <nz-form-item>
        <nz-form-label>直接上级：</nz-form-label>
        <app-employee-search></app-employee-search>
      </nz-form-item> -->
    </form>
  </nz-content>
</nz-modal>
<nz-modal
  [(nzVisible)]="isVisibleForSetReportManager"
  nzTitle="设置上级"
  (nzOnCancel)="handleCancel()"
  (nzOnOk)="handleOkForSetReportManager()"
>
  <nz-content *nzModalContent>
    <app-employee-search></app-employee-search>
  </nz-content>
</nz-modal>
<nz-modal
  [(nzVisible)]="isVisibleForSetRole"
  nzTitle="岗位设置"
  (nzOnCancel)="handleCancel()"
  (nzOnOk)="handleOkForSetRole()"
>
  <nz-content *nzModalContent>
    <app-role-search></app-role-search>
  </nz-content>
</nz-modal>
<nz-modal
  [(nzVisible)]="isVisibleForSetLevel"
  nzTitle="级别设置"
  (nzOnCancel)="handleCancel()"
  (nzOnOk)="handleOkForSetLevel()"
>
  <nz-content *nzModalContent>
    <app-level-search></app-level-search>
  </nz-content>
</nz-modal>
<nz-modal
  [(nzVisible)]="isOrganizationEdit"
  nzTitle="主组织设置"
  (nzOnCancel)="handleCancel()"
  (nzOnOk)="handleOkForSetOrganization()"
>
  <nz-content *nzModalContent>
    <app-organization-search></app-organization-search>
  </nz-content>
</nz-modal>

<nz-modal
  [(nzVisible)]="isVisibleReportManagerTree"
  nzTitle="查看汇报关系树"
  (nzOnCancel)="handleCancel()"
>
  <nz-content *nzModalContent>
    <app-employee-tree></app-employee-tree>
  </nz-content>
</nz-modal>

<nz-modal
  [nzFooter]="null"
  [(nzVisible)]="isVisibleMyReportLine"
  nzTitle="个人汇报线"
  (nzOnCancel)="handleCancel()"
>
  <nz-content *nzModalContent>
    <app-employee-report-tree></app-employee-report-tree>
  </nz-content>
</nz-modal>


<nz-modal
  [(nzVisible)]="isVisibleForSetPermission"
  nzTitle="设置模型权限"
  (nzOnCancel)="handleCancel()"
  (nzOnOk) = "saveModelPermission()"
>
  <nz-content *nzModalContent>
    <app-set-model-permission></app-set-model-permission>
  </nz-content>
</nz-modal>

<nz-modal
  [(nzVisible)]="isVisibleForSetDataPermission"
  nzTitle="设置数据权限"
  (nzOnCancel)="handleCancel()"
  (nzOnOk) = "saveDataPermission()"
>
  <nz-content *nzModalContent>
    <app-set-data-permission></app-set-data-permission>
  </nz-content>
</nz-modal>

